package com.xc.ezplan.admin.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xc.ezplan.admin.service.AdminEmailTemplateService;
import com.xc.ezplan.admin.vo.AdminEmailTemplateVo;
import com.xc.ezplan.core.base.EzResult;
import com.xc.ezplan.log.annotation.Log;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lixingchen
 * @date 2022/12/10
 * @description 邮件模板
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/email/template")
@Api(tags = "邮件模板")
public class AdminEmailTemplateController {
	private final AdminEmailTemplateService adminEmailTemplateService;

	@Log("新增邮件模板")
	@ApiOperation("新增邮件模板")
	@PostMapping
	@SaCheckPermission("mail.config.add")
	public EzResult<Object> createEmailTemplate(@Validated @RequestBody AdminEmailTemplateVo adminEmailTemplateVo) {
		adminEmailTemplateService.createEmailTemplate(adminEmailTemplateVo);
		return EzResult.ok();
	}

	@Log("更新邮件模板")
	@ApiOperation("更新邮件模板")
	@PutMapping
	@SaCheckPermission("mail.config.update")
	public EzResult<Object> updateEmailTemplate(@Validated @RequestBody AdminEmailTemplateVo adminEmailTemplateVo) {
		adminEmailTemplateService.updateEmailTemplate(adminEmailTemplateVo);
		return EzResult.ok();
	}

	@Log("删除邮件模板")
	@ApiOperation("删除邮件模板")
	@DeleteMapping
	@SaCheckPermission("mail.config.delete")
	public EzResult<Object> deleteEmailTemplate(@RequestBody List<Long> ids) {
		adminEmailTemplateService.deleteEmailTemplate(ids);
		return EzResult.ok();
	}

	@ApiOperation("查看邮件模板")
	@GetMapping
	public EzResult<Object> queryEmailTemplate(@RequestParam Long id) {
		return EzResult.ok(adminEmailTemplateService.queryEmailTemplate(id));
	}

	@ApiOperation("按条件查询模板")
	@PostMapping("/all")
	public EzResult<Object> queryAllEmailTemplate(@RequestBody(required = false) String keyWord){
		return EzResult.ok(adminEmailTemplateService.queryAllEmailTemplate(keyWord));
	}
}
